<?php
require("config.php");
$user=mysql_real_escape_string($_GET['user']);
$dummy_flag=mysql_real_escape_string($_GET['flag']);
$start_time=mysql_real_escape_string($_GET['start_time']);
$start=mysql_real_escape_string($_GET['start']);
$last_active="";
if($start==1)
{
$query=mysql_query("SELECT dummy_flag FROM users WHERE ntnet='{$user}'");
while($x=mysql_fetch_array($query))
{
$dummy_flag=$x['dummy_flag'];
}
if($dummy_flag==0) $dummy_flag=1;
else $dummy_flag=0;
}
$query=mysql_query("UPDATE users SET dummy_flag='{$dummy_flag}' WHERE ntnet='{$user}'");

if($start==1)
{
$query=mysql_query("SELECT last_active FROM users WHERE ntnet='{$user}'");
while($x=mysql_fetch_array($query))
{
$last_active=$x['last_active'];
}
$start_time=$last_active;
}
$query=mysql_query("SELECT content,time FROM messages WHERE time>'{$start_time}' ORDER BY time asc");
?>
{ "messages" : [
<?php
while($x=mysql_fetch_array($query))
{
echo "{\"content\":\"".$x['content']."\",\"time\":\"".$x['time']."\"},";
}
echo "{\"content\":\"dummy\",\"time\":\"".$start_time."\"}]}";
?>